Skip to content

fix(browser): create instance before draining cmd queue; isolate throwing commands - #383

Open
jrosendahl-opt wants to merge 1 commit into
masterfrom
fix/browser-bundle-cmd-order
Open

jrosendahl-opt wants to merge 1 commit into
masterfrom
fix/browser-bundle-cmd-order

Conversation

@jrosendahl-opt

@jrosendahl-opt jrosendahl-opt commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Why

With automatic initialization (instance_config, README "Option 1"), the CDN bundle drained window.optable.cmd before creating window.optable.instance. If the async bundle ran after DOMContentLoaded (common), the README's queued optable.instance.identify(...) threw TypeError: Cannot read properties of undefined.

Because browser/commands.ts had no try/catch, that throw aborted the bundle's top-level setup: instance was never created (no passport/pageview), utils was never set, and cmd stayed a plain array so later pushes never ran. The same happened in "Option 2" for any queued command that throws.

Found while auditing the README against the code.

What Changed

  • browser/sdk.ts: set utils and create the instance before draining the queue.
  • browser/sdk.ts: drain with lib/addons/commands (OptableCommands), which catches and logs per command, so the "a throwing command cannot break init" guarantee in lib/addons/commands.md now holds for the CDN bundle too.
  • Removed browser/commands.ts (no longer used and does not appear to be used in bundles).
  • browser/sdk.test.ts: new tests that load the bundle entry with queued commands.

…wing commands

The script-tag bundle drained window.optable.cmd before creating the
instance from instance_config, so a command queued before the async
bundle ran saw optable.instance === undefined and threw. browser/commands.ts
had no try/catch, so that throw aborted the bundle's top level: no
instance, no utils, and cmd stayed a plain array so later pushes never ran.

Create the instance first and drain the queue with the existing
lib/addons/commands OptableCommands, which catches per command. Remove
the now-unused browser/commands.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jrosendahl-opt
jrosendahl-opt requested review from a team as code owners November 10, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant